package com.yp.shopping.service.Impl;

import com.yp.shopping.bean.GetResult;
import com.yp.shopping.bean.Result;
import com.yp.shopping.dao.AdminMapper;
import com.yp.shopping.model.Admin;
import com.yp.shopping.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;


@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    public Result login(Integer account, String password, HttpSession session) {

        Admin admin = null;

        admin = adminMapper.selectByPrimaryKey(account);

        if (admin == null) {

            return GetResult.fail();
        }

        if (!admin.getPassword().equals(password)) {

            return GetResult.fail();
        }

        session.setAttribute("admin", account);

        return GetResult.success();
    }

    public Result logout(HttpSession session) {

        session.removeAttribute("admin");

        return GetResult.success();
    }
}
